package com.example.myapplication1.threademo.cutdownlatchtest;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CyclicBarrier;

/**
 * Copyright (C), 2020, 重庆八进制有限公司
 *
 * @author: weng
 * @last-modifier: weng
 * @version: 1.0
 * @create-date: 2020/12/3 11:28
 * @last-modify-date: 2020/12/3 11:28
 * @description:
 */
public class ServiceManager {

    private static ServiceManager serviceManager;
    private List<AbstractService> list = new ArrayList<>();

    public static ServiceManager getInstance() {
        synchronized (ServiceManager.class) {
            if (null == serviceManager) {
                synchronized (ServiceManager.class) {
                    serviceManager = new ServiceManager();
                }
            }
        }
        return serviceManager;
    }

    public void addService(List<AbstractService> list){
        this.list = list;
    }

    public boolean checkState() {

        for (int i = 0; i < list.size(); i++) {
            if (!list.get(i).checkState()) {
                return false;
            }
        }
        return true;
    }

    public void start() {

        for (int i = 0; i < list.size(); i++) {
            list.get(i).start();
        }

    }

}
